/*									             Can I Stay a BIT Longer?
								         The Effect of BITs on Political Survival
												   Soumyajit Mazumder
										          (Harvard University)
						
											   	    August 2015
										           Matched Results

												   
*/
use "BITMatched_Final.dta", clear

*******************************************************
*   The following set of code generates a             *
*   number of key explanatory variables               *
*******************************************************

//generate logNSBIT
gen logNSBIT = log(NSBITs+1)

//generate logSSBIT
gen logSSBIT = log(SSBITs+1)

//generate interaction b/w polity scores and logNSBIT
gen logNSBITDem = logNSBIT*polity

//generate interaction of fdi and polity scores
gen fdidem = fdi*polity

//generate log pta signed variable and interaction from Hollyer and Rosendorff paper
gen log_num_pta_sign=.
replace log_num_pta_sign=ln(num_pta_lead_sign+1)

gen pta_sign_dem = pta_lead_sign*polity
gen pta_num_dem = log_num_pta_sign*polity

gen total_bits = NSBITs+SSBITs
gen logTotBITs = log(total_bits+1)

gen TotBITsDem = logTotBITs*polity

label var logNSBIT "North-South BITs (Logged)"
label var polity "Polity II"
label var logNSBITDem "North-South BITs*Polity"
label var log_num_pta_sign "PTAs Signed (Logged)"
label var inherited_BITs "Num. BITs Inherited"
label var logrealgdppc "GDP per Capita (2005 PPP, Logged)"
label var logpop "Population (Logged)"
label var growth "GDP Growth Rate"
label var fdi "FDI (\% of GDP)"
label var fuelexports "Fuel Exports (\% of Merchandise Exports)"
label var aid "Aid (\% of GDP)"
label var fraction_reported "HRV Transparency Index"
label var under_imf "Under IMF Program"
label var wb_all "Num. World Bank Programs"
label var polconiii "Political Constraints"

**********************************************************************************************************************************************

*****************************************************
*     Cox Proportional Hazards Analysis of          *
*     North-South BITs in force on incumbent        *
*     survival.                                     *
*****************************************************

//Baseline Model
quietly eststo base: stcox logNSBIT polity logNSBITDem log_num_pta_sign inherited_BITs logrealgdppc logpop growth if OECD~=1, /// 
cluster(ccode) nohr

//Free Resources Model
quietly eststo free: stcox logNSBIT polity logNSBITDem log_num_pta_sign inherited_BITs logrealgdppc logpop growth fdi fuelexports aid if OECD~=1, /// 
cluster(ccode) nohr

//Political Risk Model
quietly eststo risk: stcox logNSBIT polity logNSBITDem log_num_pta_sign inherited_BITs logrealgdppc logpop growth fdi fuelexports aid fraction_reported if OECD~=1, /// 
cluster(ccode) nohr

//IFI Model
quietly eststo ifi: stcox logNSBIT polity logNSBITDem log_num_pta_sign inherited_BITs logrealgdppc logpop growth fdi fuelexports aid fraction_reported under_imf wb_all if OECD~=1, /// 
cluster(ccode) nohr

//Ratification Model
quietly eststo rat: stcox logNSBIT polity logNSBITDem log_num_pta_sign inherited_BITs logrealgdppc logpop growth fdi fuelexports aid fraction_reported under_imf wb_all polconiii if OECD~=1, /// 
cluster(ccode) nohr

esttab base free risk ifi rat using "Matched.tex", replace tex se label title(A Model of Political Survival: Cox Proportional Hazards Model\label{table:matched}) ///
mtitles("Model 1: Baseline" "Model 2: Free Resources" "Model 3: Political Risk" "Model 4: IFI Involvement" "Model 5: Ratification")
*****************************************************
*     Cox Non-Proportional Hazards Analysis of      *
*     North-South BITs in force on incumbent        *
*     survival.                                     *
*****************************************************

quietly stcox logNSBIT polity logNSBITDem log_num_pta_sign inherited_BITs logrealgdppc logpop growth fdi fuelexports aid fraction_reported under_imf wb_all polconiii if OECD~=1, cluster(ccode) nohr

//creating graphs for North-South BITs in force
sum logNSBIT if e(sample), de

*sets all the variables to appropriate values
local min_log_NSBIT=r(min)
local max_log_NSBIT=r(max)
local mean_log_NSBIT=r(mean)
local p75_log_NSBIT=r(p75)
local min_NSBIT_min_polity=`min_log_NSBIT'*-10
local min_NSBIT_max_polity=`min_log_NSBIT'*10
local mean_NSBIT_min_polity=`mean_log_NSBIT'*-10
local mean_NSBIT_max_polity=`mean_log_NSBIT'*10
local p75_NSBIT_min_polity=`p75_log_NSBIT'*-10
local p75_NSBIT_max_polity=`p75_log_NSBIT'*10
local max_NSBIT_min_polity=`max_log_NSBIT'*-10
local max_NSBIT_max_polity=`max_log_NSBIT'*10

stcurve, hazard at1(polity=-10  logNSBIT = `min_log_NSBIT'  logNSBITDem = `min_NSBIT_min_polity') ///
at2(polity=-10 logNSBIT = `mean_log_NSBIT' logNSBITDem = `mean_NSBIT_min_polity') ///
at3(polity=-10 logNSBIT = `p75_log_NSBIT' logNSBITDem = `p75_NSBIT_min_polity') /// 
at4(polity=-10 logNSBIT = `max_log_NSBIT' logNSBITDem = `max_NSBIT_min_polity') ///
graphregion(fcolor(white)) ytitle(Hazard Rate) xtitle(Years in Office) scheme(s2gcolor) ///
legend(label(1 No BITs) label(2 Mean BITs) label(3 75th Percentile BITs) label(4 Max BITs)) name(minpolity, replace) ///
subtitle(Minimum Polity Score)

stcurve, hazard at1(polity=10  logNSBIT = `min_log_NSBIT'  logNSBITDem =`min_NSBIT_max_polity') ///
at2(polity=10 logNSBIT = `mean_log_NSBIT' logNSBITDem = `mean_NSBIT_max_polity') ///
at3(polity=10 logNSBIT = `p75_log_NSBIT' logNSBITDem = `p75_NSBIT_max_polity') ///
at4(polity=10 logNSBIT =`max_log_NSBIT' logNSBITDem = `max_NSBIT_max_polity') ///
graphregion(fcolor(white)) ytitle(Hazard Rate) xtitle(Years in Office) scheme(s2gcolor) ///
legend(label(1 No BITs) label(2 Mean BITs) label(3 75th Percentile BITs) label(4 Max BITs)) name(maxpolity, replace) ///
subtitle(Maximum Polity Score)

graph combine minpolity maxpolity, ycommon graphregion(fcolor(white)) ///
title(Estimated Hazard Rates for North-South BITs in Force)

graph export "ConditionalEffectMatched.eps", replace

**********************************************************************************************************************************************
